package com.lykj.llw.box.adapter.sale

import android.view.View
import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lykj.lib_base.component.GlideApp
import com.lykj.llw.box.R
import com.lykj.llw.box.data.bean.response.SaleRecordResponse
import java.text.SimpleDateFormat

/**
 * ================================================
 * 出售记录适配器
 * ================================================
 *
 * @author gosha
 * @date 2023/10/23-17:54
 */
class SaleRecordAdapter :
    BaseQuickAdapter<SaleRecordResponse.DataDTO.RowsDTO, BaseViewHolder>(R.layout.item_reuse_record) {
    val sdfs = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val sdfd = SimpleDateFormat("MM/dd HH:mm")

    override fun convert(holder: BaseViewHolder, item: SaleRecordResponse.DataDTO.RowsDTO) {
        holder.setText(R.id.tv_role_name, "${item.part.gameName}")
        holder.setText(R.id.tv_server_name, "区服：${item.part.zonename}")
        holder.setText(R.id.tv_role_id, "ID：${item.part.roleid}")

        GlideApp.with(context)
            .load(item.gameIcon)
            .transition(DrawableTransitionOptions.withCrossFade())
            .into(holder.getView(R.id.iv_icon))

        holder.getView<TextView>(R.id.tv_time).visibility = View.GONE
        holder.getView<TextView>(R.id.tv_option1).visibility = View.GONE
        holder.getView<TextView>(R.id.tv_option2).visibility = View.GONE

        //FIXME:状态判断
        when (item.status) {
            -1 -> {
                holder.setText(R.id.tv_status, "审核不通过")
                holder.setTextColor(R.id.tv_status, ColorUtils.getColor(R.color.red_FFFB4242))
            }

            0 -> {
                holder.setText(R.id.tv_status, "待审核")
                holder.setTextColor(R.id.tv_status, ColorUtils.getColor(R.color.blue_FF664FC3))
//                holder.getView<TextView>(R.id.tv_option2).visibility = View.VISIBLE
            }

            1 -> {
                holder.setText(R.id.tv_status, "售卖中")
                holder.setTextColor(R.id.tv_status, ColorUtils.string2Int("#FF2FC2B0"))
                holder.getView<TextView>(R.id.tv_option1).visibility = View.VISIBLE
            }

            3 -> {
                holder.setText(R.id.tv_status, "已出售")
                holder.setTextColor(R.id.tv_status, ColorUtils.string2Int("#FF2FC2B0"))

                holder.setText(R.id.tv_time, "（${sdfd.format(sdfs.parse(item.updateTime))}完成）")
                holder.getView<TextView>(R.id.tv_time).visibility = View.VISIBLE
            }

            4 -> {
                holder.setText(R.id.tv_status, "已下架")
                holder.setTextColor(R.id.tv_status, ColorUtils.string2Int("#FF656565"))
            }
        }
    }
}